package com.pzr.soccer.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.jwt.JwtHelper;

/**
 * @Author pzr
 * @date:2022-01-04-12:09
 * @Description:
 **/
public class JwtUtil {

    public static JSONObject parseToJSONObject(String tokenStr){

        //解析token,转换成json object
        String tokenStrWithoutType=tokenStr.replace("bearer ","");
        String objStr= JwtHelper.decode(tokenStrWithoutType).getClaims();
        return JSON.parseObject(objStr);
    }

    public static long getExpiredSeconds(String tokenStr){
        return parseToJSONObject(tokenStr).getLong("exp");
    }

}
